package com.example.backend.service.impl;

import com.example.backend.mapper.RestaurantMapper;
import com.example.backend.mapper.UsertypeMapper;
import com.example.backend.pojo.User;
import com.example.backend.pojo.Usertype;
import com.example.backend.service.UsertypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsertypeServiceImpl implements UsertypeService {
    @Autowired
    private UsertypeMapper usertypeMapper;
    @Autowired
    private RestaurantMapper restaurantMapper;

    @Override
    public List<Usertype> getall() {
        List<Usertype> usertypes = usertypeMapper.getall();
        for (Usertype u:usertypes){
            u.setRes1(restaurantMapper.getRestaurantById(u.getFirst()));
            u.setRes2(restaurantMapper.getRestaurantById(u.getSecond()));
            u.setRes3(restaurantMapper.getRestaurantById(u.getThird()));
        }

        return usertypes;
    }

    @Override
    public void update(Usertype usertype) {
        usertypeMapper.update(usertype);
    }

    @Override
    public List<User> getuser(String usertypeid) {
        return usertypeMapper.getuser(usertypeid);
    }
}
